package net.jlibrary.account.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import net.jlibrary.account.service.IEmployeeManager;
import net.jlibrary.common.exception.ActionListException;
import net.jlibrary.common.project.interceptor.PurviewInterceptor;
import net.jlibrary.curbparking.action.vo.EmployeeLoginVo;
import net.jlibrary.vo.PermissionConstants;

@RestController
@RequestMapping("")
public class DefaultAction {
	@Resource
	private IEmployeeManager employeeManager;
	@RequestMapping(value = "/employeeLoginForm", method = { RequestMethod.GET })
	public ModelAndView employeeLoginForm() throws ActionListException {
		return new ModelAndView("/employeeLoginForm");
	}
	
	@RequestMapping(value = "/employeeEnter", method = { RequestMethod.POST })
	public ModelAndView employeeEnter(EmployeeLoginVo vo,HttpServletRequest request) throws ActionListException {
		vo.setIp(PurviewInterceptor.getIpaddress(request));
		String type = employeeManager.loginEmployee(vo);
		if (PermissionConstants.PERMISSION_ROLE_TYPE_BK.equals(type)) {
			return new ModelAndView("redirect:/defaultAdmin");
		} else if (PermissionConstants.PERMISSION_ROLE_TYPE_PROPERTY.equals(type)) {
			
			return new ModelAndView("redirect:/property/defaultProperty");
		} else {
			return new ModelAndView("redirect:/company/defaultCompany");
		}

	}
	
	@RequestMapping(value = "/defaultAdmin", method = { RequestMethod.GET })
	public ModelAndView defaultView() throws ActionListException {
		ModelMap map = new ModelMap();
		return new ModelAndView("/defaultAdmin",map);
	}
}
